<template>
  <div>
    <el-select
      filterable
      v-model="value"
      multiple
      @change="handleChange"
      class="mb20 mr20"
      style="width: 43%"
    >
      <el-option
        v-for="(item,index) in selectData"
        :key="index"
        :label="item.evalTypeName"
        :value="item.evalTypeId"
      />
    </el-select>
    <el-tooltip
      class="item"
      effect="light"
      content="下拉选择部门后，穿梭框左侧展示该部门下的相应人员，勾选点击按钮到右侧，点击下一步"
      placement="top"
    >
      <i class="fs16 el-icon-warning-outline"></i>
    </el-tooltip>
    <x-transfer
      @postData="handlePostdData"
      :titles="['待选加减分项目', '已选加减分项目']"
      :from="fromData"
      :to="toData"
      class="mt20"
      ref="xTransfer"
    />
  </div>
</template>

<script>
import XTransfer from '@/components/XTransfer'
// import { getDeptUserTree } from '@/api/eval'
import { getEvalParent, evalItemGet } from '@/api/eval'

export default {
  components: {
    XTransfer
  },
  data() {
    return {
      fromData: [],
      toData: [],
      selectData: [],
      value: null,
      saveArr: []
    }
  },
  mounted() {
    getEvalParent().then(res => {
      this.selectData = res.data
    })
    // getDeptUserTree().then(res => {
    //   console.log('getDeptUserTree', res)
    //   this.selectData = res.data
    // })
  },
  methods: {
    handlePostdData(arr) {
      this.toData = [...new Set([...arr])]
    },
    setArr(arr) {
      if (arr.length > 0) {
        arr.map(v => {
          v.key = v.evalItemId
          v.label = v.evalItemName
        })
        this.toData = [...new Set([...arr])]
      }
    },
    async handleChange(val) {
      if (val) {
        const res = await evalItemGet(val)
        let arr = res.data
        arr.map(v => {
          v.key = v.evalItemId
          v.label = v.evalItemName
        })

        this.$nextTick(() => {
          this.fromData = [...arr]
          this.saveArr = [...arr]
        })
      } else {
        this.fromData = []
        this.saveArr = []
      }
    },
    postData() {
      this.$refs.xTransfer.postToData()
      // if (this.toData.length > 0) {
      let arr = []
      if (this.toData.length > 0) {
        this.toData.map(j => {
          arr.push({ key: j.key })
        })
        arr.map(v => {
          v.evalItemId = v.key
        })
      }

      console.log('third', arr)
      this.$emit('postData', true, arr, 3)
      // return false
      // } else {
      //   this.$message.error('请至少选择一条')
      //   this.$emit('notSubmit', 3)
      // }
    }
  }
}
</script>